package com.hs.sfzy.controller;

import com.hs.sfzy.entity.Systemuser;
import com.hs.sfzy.service.SystemuserService;
import com.hs.sfzy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SystemuserController
 * @Description TODO
 * @Author shanglin
 * @Date 2024年10月22日 16:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/systemuser")
public class SystemuserController {
    @Autowired
    private SystemuserService systemuserService;

    @PostMapping("/login")
    public Result login(@RequestBody Systemuser systemuser){
        Systemuser login = systemuserService.login(systemuser.getUsername(), systemuser.getPassword());
        if(login == null){
            return Result.error("用户名或密码有误！");
        }
        return Result.success(login);
    }

    @PutMapping
    public Object updateUser(@RequestBody Systemuser systemuser){
        int num = systemuserService.updateUser(systemuser);
        if (num > 0) {
            return Result.success(systemuser);
        }else {
            return Result.error();
        }
    }
}
